/**
 * 主模块架构
 *
 */




(function() {

        /**
         *模块载入：下面的方式定义了当前页面，所需要引入的模块
         */
        require.config({
            baseUrl: "../..",
            paths: {
                //引入jquery.js文件
                "jquery": "assets/jquery/jquery-1.11.3.min",

                //引入bootstrap.min.js文件
                "bootstrap": "assets/bootstrap/js/bootstrap.min",

                //引入jquery.dataTables.min.js文件
                "DataTable": "assets/datatables/js/jquery.dataTables.min"

            },


            /**
             * 下面的方式定义了框架模块的依赖关系
             */
            shim : {

                jquery:{
                    exports : '$'
                },
                bootstrap : {
                    deps : [ 'jquery' ],
                    exports : 'bootstrap'
                },
                DataTable : {
                    deps : [ 'jquery' ],
                    exports : 'DataTable'
                }

            }
        });


        /**
         *主模块
         */
        require(['jquery','bootstrap','DataTable'], function ($,bootstrap,DataTable){

            var getJsonnav={
                "indexPage":"../../admin/page/page_4.html",
                "navName":[
                    {
                        "topNav" : "党群",
                        "leftNav": [
                            ["栏目1","../../admin/page/page_1.html","../../admin/image/admin/ico/jggl.png"],
                            ["栏目2","../../admin/page/page_2.html","../../admin/image/admin/ico/jggl.png"]
                        ]
                    },
                    {
                        "topNav" : "工会",
                        "leftNav": [
                            ["栏目1","../../admin/page/page_1.html","../../admin/image/admin/ico/jggl.png"],
                            ["栏目2","../../admin/page/page_2.html","../../admin/image/admin/ico/jggl.png"]
                        ]
                    },
                    {
                        "topNav" : "纪委",
                        "leftNav": [
                            ["栏目1","../../admin/page/page_1.html","../../admin/image/admin/ico/jggl.png"],
                            ["栏目2","../../admin/page/page_2.html","../../admin/image/admin/ico/jggl.png"]
                        ]
                    },
                    {
                        "topNav" : "管理",
                        "leftNav": [
                            ["机构管理","../../admin/page/page_2.html","../../admin/image/admin/ico/jggl.png"],
                            ["用户管理","../../admin/page/page_1.html","../../admin/image/admin/ico/yhgl.png"],
                            ["角色管理","../../admin/page/page_3.html","../../admin/image/admin/ico/jsgl.png"],
                            ["资源管理","../../admin/page/page_4.html","../../admin/image/admin/ico/zygl.png"],
                            ["日志管理","../../admin/page/page_5.html","../../admin/image/admin/ico/rzgl.png"],
                            ["数据字典","../../admin/page/page_6.html","../../admin/image/admin/ico/sjzd.png"]
                        ]
                    }

                ]
            }


            $(document).ready(function(){



                //遍历顶部导航栏
                for(var i=0; i<=getJsonnav.navName.length-1;i++)
                {
                    try {
                        var setHtml="<li>"+getJsonnav.navName[i].topNav+"</li>"
                        $(".setTopnav").append(setHtml)
                    } catch(e){

                    }

                }

                //初始化遍历侧边导航
                setLeftnav(getJsonnav.navName[0].topNav)

                $(document).on("click",".setTopnav li",function(){
                    $(this).parent().find("li").removeClass("class_add");
                    $(this).addClass("class_add");
                    $(".ziji_ul").html("")
                    var thisValue=$(this).html();
                    setLeftnav(thisValue)

                })

                //ajax页面载入
                var loadingDom='<div class="ds_loading_box"><i class="fa fa-spinner fa-pulse"></i>页面载入中...</div>';
                $(".user_cention_right").html(loadingDom);
                $.ajax(
                    {
                        type: "get",
                        url: getJsonnav.indexPage,
                        success:function(data)
                        {
                            $(".user_cention_right").html(data);
                        },
                        error:function()
                        {
                            alert("网络断开连接！")
                        }

                    })

                //ajax点击不同按钮载入不同页面内容

                $(document).on("click",".user_ziji",function(){
                    $(this).parent().find(".user_ziji").removeClass("user_zijiclass")
                    $(this).addClass("user_zijiclass")
                    var urlDo=$(this).html();
                    urlDo=getButtonurl(urlDo)
                    var loadingDom='<div class="ds_loading_box"><i class="fa fa-spinner fa-pulse"></i>页面载入中...</div>';
                    $(".user_cention_right").html(loadingDom);
                    $.ajax(
                        {
                            type: "get",
                            url: urlDo,
                            success:function(data)
                            {
                                $(".user_cention_right").html(data);
                            },
                            error:function()
                            {
                                alert("网络断开连接！")
                            }

                        })
                })

                //设置left页面的全局高度铺满全屏
                setHeightleft("user_cention_left");
                setHeightleft("user_cention_right");
                setWidthleft("user_cention_right");
                window.onresize=function(){
                    setHeightleft("user_cention_left");
                    setHeightleft("user_cention_right");
                    setWidthleft("user_cention_right");
                }

                $(".user_fuji").click(function(){
                    if( $(this).hasClass("jt_right"))
                    {
                        $(this).removeClass("jt_right");
                        $(this).addClass("jt_down");
                    }else
                    {
                        $(this).addClass("jt_right");
                        $(this).removeClass("jt_down");
                    }
                    if( $(this).next().hasClass("ziji_ul"))
                    {
                        $(this).next().fadeToggle(100);
                    }
                })

                $(".shouqi").click(function(){
                    if($(this).hasClass("zk"))
                    {
                        $(this).removeClass("zk");
                        $(".user_cention_left").fadeIn(0);
                        $(this).css("left","200px");
                        $(this).html("<<")
                        $(this).attr("title","点击收起");
                        var wWidth=$(window).width();
                        var wWidththis=wWidth-194;
                        $(".user_cention_right").css("width",""+wWidththis+"px");

                    }else
                    {
                        $(this).addClass("zk");
                        $(".user_cention_left").fadeOut(0);
                        $(this).css("left","0px");
                        $(this).html(">>")
                        $(this).attr("title","点击展开");
                        var wWidth=$(window).width();
                        var wWidththis=wWidth-10;
                        $(".user_cention_right").css("width",""+wWidththis+"px");
                    }
                })

                //遍历侧边导航栏
                function setLeftnav(getTopnav){

                    for(var i=0; i<=getJsonnav.navName.length-1;i++)
                    {
                        try {
                        if(getJsonnav.navName[i].topNav==getTopnav)
                        {
                            for(var j=0; j<=getJsonnav.navName[i].leftNav.length-1;j++)
                            {

                                var setHtml="<li class='user_ziji' style='background: url("+getJsonnav.navName[i].leftNav[j][2]+") no-repeat  0px -36px '>"+getJsonnav.navName[i].leftNav[j][0]+"</li>"
                                $(".ziji_ul").append(setHtml)

                            }
                        }
                        } catch (e){

                        }
                    }
                }

                //获取每个侧边按钮的URL
                function getButtonurl(getButton){

                    for(var i=0; i<=getJsonnav.navName.length-1;i++)
                    {
                        for(var j=0; j<=getJsonnav.navName[i].leftNav.length-1;j++)
                        {
                            try {
                            if(getJsonnav.navName[i].leftNav[j][0]==getButton){

                                return getJsonnav.navName[i].leftNav[j][1];

                            }
                            }catch (e){}
                        }
                    }
                }

                //设置left页面的全局高度铺满全屏
                function setHeightleft(className){
                    var wHeight=$(window).height();
                    var wHeightthis=wHeight-50;
                    $("."+className+"").css("height",""+wHeightthis+"px");
                }
                function setWidthleft(className){
                    var wWidth=$(window).width();
                    var wWidththis=wWidth-194;
                    $("."+className+"").css("width",""+wWidththis+"px");
                }

            })
            // some code here
        });


})(this);



